package com.unitd.frame.sso.common.enums;

/**
 * @desc 算法类型枚举类, 用于定义SSO工程中采用的算法类型定义
 * @filename AlgorithmEnum.java
 * @copyright www.pactera.com.cn
 * @author Hudan
 * @version 1.0
 * @date 2016/10/27
 */
public enum AlgorithmEnum {
	DES("DES", "DES 加密"),
	AES("AES", "AES 加密"),
	BLOWFISH("BLOWFISH", "Blowfish 加密"),
	RC2("RC2", "RC2 加密"),
	RC4("RC4", "RC4 加密");

	/** 算法类型,主键 */
	private final String key;
	/** 描述 */
	private final String desc;

	AlgorithmEnum(final String key, final String desc) {
		this.key = key;
		this.desc = desc;
	}

	public String getKey() {
		return this.key;
	}

	public String getDesc() {
		return this.desc;
	}

	/**
	 * @desc 根据算法类型字符串获取对应的算法枚举对象
	 * @param algorithmType 算法类型
	 * @return AlgorithmEnum
	 */
	public static AlgorithmEnum convert(String algorithmType) {
		// 默认采用RC4算法加解密
		AlgorithmEnum algorithm = AlgorithmEnum.RC4;

		if (null != algorithmType) {
			AlgorithmEnum[] algs = AlgorithmEnum.values();
			for (AlgorithmEnum alg : algs) {
				if (alg.getKey().equals(algorithmType)) {
					algorithm = alg;
					break;
				}
			}
		}
		return algorithm;
	}
}